package migrations

import (
	"database/sql"
	"time"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

// http://sql2struct.atotoa.com/
func init() {

	// 司机发布的行程表
	type Trip struct {
		models.BaseModel

		UserId         uint64    `gorm:"column:user_id" db:"user_id;index;" json:"user_id" form:"user_id"`
		DriverId       uint64    `gorm:"column:driver_id;comment:司机id;index;" db:"driver_id" json:"driver_id" form:"driver_id"`
		VehicleId      uint64    `gorm:"column:vehicle_id;comment:车辆id;index;" db:"vehicle_id" json:"vehicle_id" form:"vehicle_id"` //车辆ID
		StartLocation  uint64    `gorm:"column:start_location;comment:起始地址id;index;" db:"start_location" json:"start_location" form:"start_location"`
		EndLocation    uint64    `gorm:"column:end_location;comment:终点地址id;index;" db:"end_location" json:"end_location" form:"end_location"`
		DepartureTime  time.Time `gorm:"column:departure_time;type:timestamp;comment:出发时间;index;" db:"departure_time" json:"departure_time" form:"departure_time"` //出发时间
		Deadline       time.Time `gorm:"column:deadline;type:timestamp;comment:拼车截止时间;index;" db:"deadline" json:"deadline" form:"deadline"`                       //拼车截止时间
		TotalSeats     uint8     `gorm:"column:total_seats;comment:总座位数;" db:"total_seats" json:"total_seats" form:"total_seats"`                                  //总座位数
		AvailableSeats uint8     `gorm:"column:available_seats;comment:剩余座位数;" db:"available_seats" json:"available_seats" form:"available_seats"`                 //可用座位数
		Price          float64   `gorm:"column:price;comment:单价;index;" db:"price" json:"price" form:"price"`                                                      //每个座位的价格
		Itinerary      string    `gorm:"type:varchar(255);comment:行程安排;" db:"itinerary" json:"itinerary" form:"itinerary"`                                         //行程安排
		Status         uint8     `gorm:"column:status;comment:行程状态 1进行中 2等待发车 3司机取消 4已完成;index;" db:"status" json:"status" form:"status"`                          // 行程状态

		models.CommonTimestampsField
	}

	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&Trip{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&Trip{})
	}

	migrate.Add("2023_07_18_134435_add_trips_table", up, down)
}
